package com.lancoo.rxretrofitlibrary;

import com.google.gson.Gson;
import com.lancoo.rxretrofitlibrary.Api.BaseResultEntity;

import java.io.IOException;
import java.lang.reflect.Type;

import okhttp3.Response;
import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * Created by tangminglong on 17/5/15.
 */

public class GsonResponseBodyConverter<T extends BaseResultEntity> implements Converter<ResponseBody,T> {
    private final Gson gson;
    private final Type type;

    public GsonResponseBodyConverter(Gson gson, Type type) {
        this.gson = gson;
        this.type = type;
    }

    @Override
    public T convert(ResponseBody value) throws IOException {
        String response = value.string();
        //Response httpResult = gson.fromJson(response,Response.class);
        //if (httpResult.code())

        return gson.fromJson(response,type);
    }


}
